﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Security.Cryptography;
using System.Text;
using MySql.Data.MySqlClient;
using System.Security.Principal;
using System.Web.Security;

public partial class AddEmployee : System.Web.UI.Page
{
    DBAcess db = new DBAcess();
    protected void Page_Load(object sender, EventArgs e)
    {
        Page.Title = "Add Employees | Nexus-Z Auto Rental";
        Button2.CausesValidation = false;
        if (Session["role"] == null)
        {
            Response.Redirect("../../Default.aspx");
        }
    }
    protected void Button1_Click(object sender, EventArgs e) {
        db.open();
        MySqlCommand cmd = new MySqlCommand( "insert into employees(first_name, last_name, house_no, street, apartment_no, city, zip_code, state, phone_no, birth_date, hiring_date, password, admin_id) values(' " + TextBox2.Text + " ','" + TextBox3.Text + "','" + TextBox4.Text + "','" + TextBox5.Text + "','" + TextBox6.Text + "','" + TextBox7.Text + "','" + TextBox8.Text + "','" + DropDownList1.SelectedValue + "','" + TextBox9.Text + "','" + TextBox10.Text + "','" + TextBox1.Text + "', '" + getMd5Hash( "nexusZ" ) + "', '" + Session["adminID"] + "')", db.returnCon() );
        cmd.ExecuteNonQuery();
        db.close();
        Response.Redirect("~/Admin/Employee/EditEmployee.aspx");
    }

    static string getMd5Hash(string input) {
        MD5 md5Hasher = MD5.Create();

        byte[] data = md5Hasher.ComputeHash( Encoding.Default.GetBytes( input ) );

        StringBuilder sBuilder = new StringBuilder();
        for ( int i = 0; i < data.Length; i++ ) {
            sBuilder.Append( data[i].ToString( "x2" ) );
        }

        return sBuilder.ToString();

    }
}